package com.mc.servlet;

import com.mc.bean.Jury;
import com.mc.service.JuryService;
import com.mc.service.impl.JuryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author fyp
 * 评委添加控制器
 */
@WebServlet("/juryadd.action")
public class JuryAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建评委逻辑对象
        JuryService juryService = new JuryServiceImpl();
        String juryname = req.getParameter("juryname");
        String jurytel = req.getParameter("jurytel");
        String jurypassword = req.getParameter("jurypassword");
        String jage = req.getParameter("juryage");
        String jurysex = req.getParameter("jurysex");
        //控制台输出打印
        System.out.println(juryname);
        System.out.println(jurytel);
        System.out.println(jurypassword);
        System.out.println(jurysex);
        System.out.println(jage);
        //类型转换，将id转换成int类型
        int juryage = Integer.valueOf(jage);
        Jury jury = new Jury(juryname, jurytel, jurypassword, juryage, jurysex);
        boolean flag = juryService.add(jury);
        System.out.println(flag);
        //重定向
        String type = req.getParameter("type");
        if (type.equals("1")) {
            resp.sendRedirect("jurylist.action");
        } else if(type.equals("2")){
            resp.sendRedirect("userlogin.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
